package com.hoshiicloud.goods.controller;


import com.hoshiicloud.common.rpc.Response;
import com.hoshiicloud.goods.dto.sku.SkuDTO;
import com.hoshiicloud.goods.param.sku.LockSkuStockParam;
import com.hoshiicloud.goods.service.SkuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 扩展商品表SKU 控制器
 * </p>
 *
 * @author zhangshuhu
 * @since 2019-05-05
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/goods/sku-info")
@Api(value = "SKU", tags = {"SKU"})
public class SkuController {

    @Autowired
    private SkuService skuService;


    /**
     * 查询总店库存
     *
     * @param ids ids
     * @return Response
     */
    @PostMapping("/queryHeadOfficeSkuStockByIds")
    @ApiOperation(value = "根据扩展skuid查询总店商品库存信息")
    public Response<Map<Long, SkuDTO>> queryHeadOfficeSkuStockByIds(@RequestBody List<Long> cartVoIdList) {
        return Response.data(skuService.queryHeadOfficeSkuStockByIds(cartVoIdList));
    }

    /**
     * 根据扩展skuid查询商品库存信息
     *
     * @param ids
     * @return
     */
    @ApiOperation(value = "根据扩展skuid查询商品库存信息")
    @RequestMapping(value = "/getSkuStockByIds", method = RequestMethod.POST)
    public Response<Map<Long, SkuDTO>> querySKuStockByIds(@RequestBody List<Long> ids) {
        return Response.data(skuService.querySKuStockByIds(ids));
    }

    /**
     * 冻结库存
     *
     * @param lockSkuStocks
     * @return
     */
    @ApiOperation(value = "冻结库存")
    @RequestMapping(value = "/lockSkuStock", method = RequestMethod.POST)
    public Response lockSkuStock(@RequestBody List<LockSkuStockParam> lockSkuStocks) {
        skuService.lockSkuStock(lockSkuStocks);
        return Response.success("冻结库存成功");
    }

    /**
     * 解冻库存
     *
     * @param lockSkuStocks
     * @return
     */
    @ApiOperation(value = "解冻库存")
    @RequestMapping(value = "/unLockSkuStock", method = RequestMethod.POST)
    public Response unLockSkuStock(@RequestBody List<LockSkuStockParam> lockSkuStocks) {
        skuService.unLockSkuStock(lockSkuStocks);
        return Response.success("解冻库存成功");
    }


    /**
     * 根据扩展skuid查询商品信息
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "根据扩展skuid查询商品信息")
    @RequestMapping(value = "/getExtSku", method = RequestMethod.POST)
    public Response<SkuDTO> getExtSku(@RequestBody Long id) {
        return Response.data(skuService.getExtSku(id));
    }

}